package edu.sctu.xialei.May.day20150529one;

import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;

/**
 * Created by Administrator on 5/29/2015.
 */
//      学生信息处理类
public class StudentInfoUtil {

    Scanner input = new Scanner(System.in);

    //      学生信息录入
    public HashMap<Integer, StudentInfo> setStudentInfo() {

        HashMap<Integer, StudentInfo> allStudentInfomap = new HashMap<Integer, StudentInfo>();

        System.out.println("\n\n*** 现在录入信息 ***");

        for (String check = "1"; check.equals("1"); check = input.next()) {
            StudentInfo studentInfo = new StudentInfo();

            System.out.println("\n姓名：");
            studentInfo.name = input.next();

            System.out.println("学号：");
            studentInfo.number = input.nextInt();

            System.out.println("成绩：");
            studentInfo.grade = input.nextFloat();

            System.out.println("地址 (某市) ：");
            studentInfo.address = input.next();

            allStudentInfomap.put(studentInfo.number, studentInfo);
            System.out.println("！！！！   输入 1 继续录入信息，否则退出     ！！！！");
        }

        return allStudentInfomap;
    }


    //    对三号学生认证
    public HashMap<Integer,StudentInfo> judgeSanHao(HashMap<Integer, StudentInfo> studentInfoHashMap) {

        Collection<StudentInfo> values = studentInfoHashMap.values();

        for (StudentInfo studentInfo : values) {

            if (studentInfo.grade > 90) {
                studentInfo.is_sanhao = true;
            }
        }

        return studentInfoHashMap;
    }

//    提取三好生信息
    public HashMap<Integer,StudentInfo> selectSanHaoStudent(HashMap<Integer,StudentInfo> map){
        HashMap<Integer,StudentInfo> sanHaoStudentMap = new HashMap<Integer,StudentInfo>();

        Collection<StudentInfo> values = map.values();

        for (StudentInfo studentInfo : values) {

            if (studentInfo.is_sanhao == true) {
                sanHaoStudentMap.put(studentInfo.number,studentInfo);
            }
        }
        return sanHaoStudentMap;
    }


    public HashMap<Integer,StudentInfo> judgeAddress(HashMap<Integer,StudentInfo> map,String address) {
        HashMap<Integer,StudentInfo> addressStudentMap = new HashMap<Integer,StudentInfo>();

        Collection<StudentInfo> values = map.values();

        for (StudentInfo studentInfo : values) {

            if (studentInfo.address.equals(address)) {
               addressStudentMap.put(studentInfo.number,studentInfo);
            }
        }
        return addressStudentMap;
    }
}
